<!doctype html>
<html>
<head>
  <title>Learning javascript</title>
  <meta charset="utf-8" />
  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <style>
  </style>
</head>

<body>
<div>
  <p>How many fingers are you holding up?</p>
  <input id="myNumber"></input>
  <button id="guess">Guess!</button>
  <script type="text/javascript">
    document.getElementById("guess").onclick=function(){
      var myNumber=document.getElementById("myNumber").value;
      var lowerLimit=0;
      var upperLimit=6;
      if (myNumber==Number.parseInt(myNumber) && lowerLimit <= myNumber && myNumber < upperLimit) {
        var x=0;
        var guessCount=1;
        var gotIt=false;
        while (false==gotIt) {
          x=Math.floor(Math.random()*6);
          if (x==myNumber) {
            gotIt=true;
          }
          else {
            guessCount++;
          }
        }
        alert("Number is " + x + ". Guessed " + guessCount + " times.");
      }
    }
  </script>
</div>
</body>
</html>
